//main.js
const sharePost = require('../../request/sharePost.js')
var WxParse = require('../../wxParse/wxParse.js')
//获取应用实例
const app = getApp()

Page({
  data: {
    isSalesman:false,
    userInfo: {},
    url: '',
    userType: '',
    isParts:false,
    imgUrls: [],
    productList: [
      { src: '../../assets/images/common/product1.jpg'},
      { src: '../../assets/images/common/product2.jpg' },
      { src: '../../assets/images/common/product3.jpg' },
      { src: '../../assets/images/common/product4.jpg' },
      { src: '../../assets/images/common/product5.jpg' },
      { src: '../../assets/images/common/product6.jpg' },
    ],
    indicatorDots: true, //小点
    indicatorColor: "white",//指示点颜色
    activeColor: "coral",//当前选中的指示点颜色
    autoplay: false, //是否自动轮播
    interval: 3000, //间隔时间
    duration: 1000, //滑动时间
  },
  /**
   * 弹出框蒙层截断touchmove事件
   */
  preventTouchMove: function () { },
  /**
   * 获取轮播图片
   */
  getCarousels: function () {
    sharePost.getCarousels({}).then(res => {
      console.log('imgUrl', res)
      this.setData({
        imgUrls: res.data
      });
    })
  },
  onLoad: function () {
    this.app = getApp();
    let that = this
    console.log('app.globalData.user_typeindex', app.globalData.user_type)
    this.setData({
      userType: app.globalData.info.user_type
    })
    that.getCarousels()
    //获取推荐新闻列表
    sharePost.getNews({}).then(res => {

      if (res.success){
        var rt = res.data;
        var newsId=""
        for(var i=0;i<rt.length;i++){

          if (rt[i].news_type==4){
            newsId = rt[i]._id;
            break;
          }
        }

        if(newsId!=""){

          sharePost.getNewsInf({ newId: newsId }).then(res => {
            console.log('配件展示详情', res.data)
            this.setData({
              newsInfo: res.data[0]
            })
            //显示富文本信息
            var that = this;

            that.setData({
              isParts: true
            })
            //console.log("======>" + con.require("<video","<video custom-cache=\"{{false}}\" "));
            WxParse.wxParse('article', 'html', res.data[0].news_content, that, 5);

          })
        }
      }
    })
  },
  goToUrl(e) {
    console.log("sksdjfkd")
    let that = this
    that.setData({
      url: e.currentTarget.dataset.url
    })
    wx.navigateTo({
      url: that.data.url,
    })
  },
  //跳转到小程序商城
  goToShoppingMall(e){
    wx.navigateToMiniProgram({
      appId: app.globalData.mallAppId,//要调转小程序的appid
      path:"pages/main/main",//跳转的目标页
      extraData:{
        open:"100"
      },
      success(res){
        //打开成功
        console.log("打开成功");
      }
    })
  },
  urlEvent: function (e) {
    console.log(e, '子组件传过来的值')
    let that = this
    that.setData({
      url: e.detail
    })
    wx.navigateTo({
      url: that.data.url,
    })
  },
  //页面展示时，触发动画
  onShow: function () {
    this.app.slideupshow(this, 'slide_up1', -100, 1)
    setTimeout(function () {
      this.app.slideupshow(this, 'slide_up2', -100, 1)
    }.bind(this), 200);
    setTimeout(function () {
      this.app.slideupshow(this, 'slide_up3', -100, 1)
    }.bind(this), 400);
    setTimeout(function () {
      this.app.slideupshow(this, 'slide_up4', -100, 1)
    }.bind(this), 600);
    setTimeout(function () {
      this.app.slideupshow(this, 'slide_up5', -100, 1)
    }.bind(this), 800);
    setTimeout(function () {
      this.app.slideupshow(this, 'slide_up6', -100, 1)
    }.bind(this), 1000);
    setTimeout(function () {
      this.app.slideupshow(this, 'slide_up7', -100, 1)
    }.bind(this), 1200);
    setTimeout(function () {
      this.app.slideupshow(this, 'slide_up8', -100, 1)
    }.bind(this), 1400);
  }
})
